fix: adapt to ChatGPT API v2 metadata format + Turnstile solver support#6
Open
abczsl520 wants to merge 1 commit into432539:mainfrom
Open
fix: adapt to ChatGPT API v2 metadata format + Turnstile solver support#6abczsl520 wants to merge 1 commit into432539:mainfrom
abczsl520 wants to merge 1 commit into432539:mainfrom
Conversation
…upport ## Problem ChatGPT upstream API changed the metadata format for image generation tool messages: - Old format: `metadata.async_task_type = "image_gen"` - New format: `metadata.image_gen_title = "..."` (final) or `metadata.async_source = "..."` (preview) This caused `ExtractImageToolMsgs` to match zero tool messages, making poll always timeout with no images returned. Additionally, the upstream now requires Turnstile challenge solving for the two-step chat-requirements flow (prepare → finalize). ## Changes ### Core fix: metadata compatibility (image.go) - `ExtractImageToolMsgs` now matches tool messages by any of: `async_task_type=image_gen` (old), `image_gen_title` (new final), or `async_source` (new preview) ### Turnstile solver support - New `TurnstileSolver` interface signature: `Solve(ctx, dx, token)` adds the `token` (p_value) parameter needed for bytecode decryption - New `HTTPTurnstileSolver`: delegates to an external HTTP service - New config field: `upstream.turnstile_solver_url` - Wiring in `runner.go` and `main.go` - `ChatRequirementsPrepareResp.PToken` field to pass the requirements_token through to the solver ### Tuning - Poll interval: 3s → 15s (avoids 429 rate limiting from upstream) - Consecutive 429 tolerance: 3 → 10 - PerAttemptTimeout: 6min → 10min (image gen can take 3-5 min) - PollMaxWait: 300s → 480s
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
ChatGPT upstream API changed the metadata format for image generation tool messages:
metadata.async_task_type = "image_gen"metadata.image_gen_title = "..."(final image) ormetadata.async_source = "..."(preview)This caused
ExtractImageToolMsgsto match zero tool messages during poll, making image generation always timeout with no results.Additionally, the upstream now requires Turnstile challenge solving for the two-step chat-requirements flow (prepare → finalize).
Changes
1. Core fix: metadata compatibility (
image.go)ExtractImageToolMsgsnow matches tool messages by any of:async_task_type = "image_gen"(old format, backward compatible)image_gen_title != ""(new format, final image)async_source != ""(new format, preview image)2. Turnstile solver support
TurnstileSolverinterface: addedtokenparameter toSolve(ctx, dx, token)— thetokenis thep_value/ requirements_token needed for Turnstile bytecode decryptionHTTPTurnstileSolver: delegates to an external HTTP microservice (e.g. a Python VM decompiler)upstream.turnstile_solver_url— when set, enables the two-step prepare → solve → finalize flow3. Tuning
Testing
Tested with a ChatGPT Plus account:
/v1/images/generations: ✅ (HTTP 200, 1-2 images returned)/api/me/playground/image: ✅/p/img/endpoint: ✅